package com.wx.springboot.step7.controller;

import com.wx.springboot.step7.entity.User;
import com.wx.springboot.step7.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "jpa demo")
@RequestMapping("/jpa")
@RestController
@Slf4j
public class JpaController {

    @Autowired
    private UserService userService;

    @ApiOperation("保存数据")
    @PostMapping("/save")
    public void saveUser(int count){
        userService.saveUser(count);
    }

    @ApiOperation("基础查询演示")
    @GetMapping("/query/base")
    public void queryBase(){
        userService.queryBase();
    }

    @ApiOperation("分页查询演示")
    @GetMapping("/query/page")
    public Page<User> queryPage(Integer page,Integer size){
        return userService.queryPage(page, size);
    }


    @ApiOperation("自定义sql查询演示")
    @GetMapping("/query/sql")
    public void querySql(){
        userService.querySql();
    }
}
